<!DOCTYPE html>
<html>
<head>
    <title>更改挂号--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>


    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
</head>
<body>
<form id="myForm" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <input type="hidden" id="id" name="id">
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td ><input type="text" id="registerName" name="registerName"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">身份证号</td>
            <td><input type="text" id="idNumber" name="idNumber"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">挂号费</td>
            <td><input type="text" id="regPrice" name="regPrice"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">社保号</td>
            <td><input type="text" id="medicalNumber" name="medicalNumber"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">联系电话</td>
            <td><input type="text" id="phone" name="phone"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">是否自费</td>
            <td>
                <input type="radio" name="selfPrice" id="r1" value="1"/>是
                <input type="radio" name="selfPrice" id="r0" value="0"/>否
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">性别</td>
            <td>
                <input type="radio" name="sex" id="s1" value="1"/>男&nbsp;&nbsp;&nbsp;
                <input type="radio" name="sex" id="s0" value="0"/>女
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">年龄</td>
            <td><input type="text" id="age" name="age"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">职业</td>
            <td><input type="text" id="profession" name="profession"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">初复诊</td>
            <td>
                <input type="radio" name="lookDoctor" id="l1" value="1"/>复诊&nbsp;
                <input type="radio" name="lookDoctor" id="l0" value="0"/>初诊
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">所挂科室</td>
            <td><select id="department" name="department" onchange="getDoctorByDept(0)"></select></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">指定医生</td>
            <td><select id="doctorId" name="doctorId"></select></td>
        </tr>

        <tr>
            <td width="10%" class="tableleft">备注</td>
            <td><input id="note" name="note"></td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <button type="button" class="btn btn-success" onclick="update()">保存</button>
                    <button type="button" class="btn btn-success" onclick="black()">返回列表</button>
                </center>
            </td>
        </tr>
    </table>
</form>
<script>
    loadFunction();

    //显示科室信息
    function showDept(deptId) {
        $.ajax({
            type: "GET",
            url: "/dept/findDept",
            dataType: "json",
            async:false,
            success: function (vo) {
                let data = vo.list;
                let str = "<option>未选择</option>";
                for (let i = 0; i < data.length; i++) {
                    if(deptId==data[i].deptId){
                        str += "<option  value=\" " + data[i].deptId + "\" selected='selected' >" + data[i].deptName + "</option>"
                    }else {
                        str += "<option  value=\" " + data[i].deptId + "\" >" + data[i].deptName + "</option>"
                    }
                }
                $("#department").html(str);

            },
        })
    }

    //显示所选科室的医生
    function getDoctorByDept(id) {
        var department = $("#department option:checked").val();
        $.ajax({
            type: "GET",
            url: "/Doctor/getDoctorByDept?department="+department,
            success: function (list) {
                var str="";
                for(var i=0;i<list.length;i++){
                    if(id==list[i].id){
                        str += "<option  value=\" " + list[i].id + "\" selected='selected'>" + list[i].doctorName + "</option>"
                    }else {
                        str += "<option  value=\" " + list[i].id + "\" >" + list[i].doctorName + "</option>"
                    }
                }
                $("#doctorId").html(str);
            },
        })
    }

    function loadFunction() {
        //获取url
        (function($){
            $.getUrlParam
                = function(name)
            {
                var reg
                    = new RegExp("(^|&)"+
                    name +"=([^&]*)(&|$)");
                var r
                    = window.location.search.substr(1).match(reg);
                if (r!=null) return unescape(r[2]); return null;
            }
        })(jQuery);
        var id = $.getUrlParam('id');
        $.ajax({
            type: "GET",
            url: "/HMC/findByID?id="+id,
            success: function(vo) {
               var obj=vo.obj;
               $("#id").val(obj.id);
               $("#registerName").val(obj.registerName);
               $("#idNumber").val(obj.idNumber);
               $("#regPrice").val(obj.regPrice);
               $("#medicalNumber").val(obj.medicalNumber);
               $("#phone").val(obj.phone);
               obj.selfPrice==1?$("#r1").prop('checked', true) : $("#r0").prop('checked', true);
               obj.sex==1 ? $("#s1").prop('checked', true) : $("#s0").prop('checked', true);
               $("#age").val(obj.age);
               $("#profession").val(obj.profession);
               obj.lookDoctor==1?$("#l1").prop('checked', true) : $("#l0").prop('checked', true);
               showDept(obj.dept.deptId);
               getDoctorByDept(obj.doctorId);
               $("#note").val(obj.note);
            }
        });
    }

    function update(){
        //非空校验
        if($("#registerName").val()=="" || $("#regPrice").val()=="" || $("#age").val()==""
            || $("#department").val()=="" || $("#doctorId").val()==""){
            alert("有主要字段为空");
            return false;
        }
        $.ajax({
            url:"/register/updateRegister",
            type:"POST",
            data:$("#myForm").serialize(),
            dataType:"json",
            success:function (vo) {
                alert(vo.msg);
                if(vo.code==200){
                    black();
                }
            }
        });
    }

    function black() {
        window.location.href="index.html";
    }
</script>
</body>
</html>